package cpm.atguigu.gulimall.seckill.controller;

import com.atguigu.common.utils.R;
import cpm.atguigu.gulimall.seckill.service.SeckillService;
import cpm.atguigu.gulimall.seckill.to.SeckillSkuRedisTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用来查询当前参与的秒杀商品。
 * 我们在前端页面发送AJAX进行查询
 */
@RestController
public class SeckillController {

    @Resource
    private SeckillService seckillService;

    /**
     * 返回当前时间可以参与的秒杀商品信息
     * @return
     */
    @GetMapping("/cuuentSeckillSkus")
    public R getCuuentSeckillSkus(){
        List<SeckillSkuRedisTo> list =  seckillService.getCuuentSeckillSkus();
        return R.ok().setData(list);
    }

    @GetMapping("/kill")
    public R seckill(@RequestParam("killId") String killId, //秒杀id,就是秒杀活动id_skuId
                     @RequestParam("key") String key,    //商品的随机码
                     @RequestParam("num") Integer num){  //秒杀件数
        String ordrSn = seckillService.kill(killId,key,num);

        return null;
    }
}
